<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>

<script>
	
	function beforeUpload()
	{
		if ($("#materialName").hasClass("required") && $("#materialName").val() == "")
		{
			alertMsg.error("请填写材料名称..");
			return;
		}
		
		if ($("#formFile").val() == "")
		{
			alertMsg.error("请选择需要时上传的文件...");
			return;
		}
		
		var ajaxbg = $("#background,#progressBar");
		ajaxbg.show();
		$("#upForm").submit();
	}
	
	function afterUpload(code)
	{
		var ajaxbg = $("#background,#progressBar");
		ajaxbg.hide();
		
		if (code == "1") 
		{
			alertMsg.correct("文件上传成功...")
		} 
		else 
		{
			alertMsg.error("文件上传失败...");
			return;
		}
		
		if (navTab.getCurrentTabId() == "menu_item_project_post") {
			var subTab = navTab.getCurrentPanel().find(".tabsHeaderContent").find("li.selected");
			if (subTab.size() > 0) {
				$.pdialog.closeCurrent();
				$(subTab).find("a").trigger("click");
			}
		} else {	
			// 重新加载当前弹框页面数据
			var dialogs = $(".dialog");
			if ($.pdialog._current != null) {
				if (dialogs.length > 1) {
					$.pdialog.switchDialog($(dialogs[dialogs.length - 2]));
					$.pdialog.close($(dialogs[dialogs.length - 1]));
				} else {
					$.pdialog.closeCurrent();
				}
				
				//$("li.selected", $.pdialog._current).trigger("click");
				$.pdialog.reload("app/project/base.do?action=dialogProjectPage&pid=${project.id}&op=post_stuff&currentindex=1");
			}
		}
		
	}
	
</script>

<!-- Body -->
<iframe name='hidden_frame' id="hidden_frame" style="display:none"></iframe>
<form id="upForm" method="post" enctype="multipart/form-data" action="file-upload" class="pageForm required-validate" target="hidden_frame">
	<div class="pageContent">
		<div class="pageFormContent" layoutH="55" style="border-top: none; background-color: #FFF">
			<table cellpadding="0" cellspacing="0" width="98%" border="0" style="border-collapse: collapse; border-color: #797979; margin: 0 auto;">
				<tr>
					<td style="line-height: 30px;">材料名称：</td>
					<td><input type="text" id="materialName" name="materialName" value="${material.materialName}" ${material ne null ? 'readonly' : ''} class="${mid eq null ? 'required' : ''}" /></td>
				</tr>
				<tr>
					<td style="line-height: 30px;">材料分类：</td>
					<td>
						<select name="materialRoot" ${material ne null ? 'disabled' : ''} class="">
							<logic:present name="project" property="materials">
								<logic:iterate name="project" property="materials" id="cat">
									<option value="${cat.id}">${cat.materialName}</option>
								</logic:iterate>
							</logic:present>
						</select>
					</td>
				</tr>
				<tr>
					<td style="line-height: 30px;">材料性质：</td>
					<td>
						<select name="materialType" ${material ne null || mid eq null ? 'disabled' : ''} class="">
							<option value="0" ${material ne null && material.materialType eq 0 ? 'selected' : ''}>建议提交</option>
							<option value="1" ${material ne null && material.materialType eq 1 ? 'selected' : ''}>必须提交</option>
							<option value="2" ${mid eq null || (material ne null && material.materialType eq 2) ? 'selected' : ''}>补充材料</option>
						</select>
						<c:if test="${mid eq null}"><input type="hidden" value="2" name="materialType" /></c:if>
					</td>
				</tr>
				<tr>
					<td style="line-height: 30px;">材料位置：</td>
					<td>
						<input id="formFile" name="formFile" type="file" />
					</td>
				</tr>
			</table>
			
			<div style=" border-top: 1px solid #DDD; padding-top: 10px; margin-top: 10px;">
				<table width="100%">
					<tr>
						<td>上传人：</td>
						<td>
							<input name="poster.id" value="${currentUser ne null ? currentUser.id : ''}"" type="hidden"/>
							<input class="required" name="poster.username" value="${currentUser ne null ? currentUser.username : ''}" type="text" postField="search" suggestFields="username,userNo" suggestUrl="app/base.do?action=lookupUserByName" lookupGroup="poster" style="width: 80px"/>
						</td>
						<td>上传时间：</td>
						<td><input type="text" class="date required textInput" name="postTime" style="width: 80px" value="<fmt:formatDate value='${date}' type='date' pattern='yyyy-MM-dd'/>"/></td>
					</tr>
				</table>
			</div>
		</div>
	</div>
	<div class="formBar">
		<ul>
			<li>
				<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
			</li>
			<li id="btn_allocate">
				<div class="buttonActive"><div class="buttonContent"><button type="button" onclick="beforeUpload()">提交</button></div></div>
			</li>
		</ul>
	</div>
	<input type="hidden" name="pid" value="${project ne null ? project.id : -1}" />
	<input type="hidden" name="mid" value="${material ne null ? material.id : -1}" />
</form>
